package com.venus.plan.planresource.service.impl;

import java.util.List;

import com.venus.common.service.impl.BaseServiceImpl;
import com.venus.common.utils.ConditionUtil;
import com.venus.component.page.PageInfo;
import com.venus.model.PlanResourceVO;
import com.venus.model.PubUserVO;
import com.venus.plan.planresource.dao.IPlanResourceDAO;
import com.venus.plan.planresource.service.IPlanResourceService;
import com.venus.plan.plantargetresource.dao.IPlanTargetResourceDAO;

public class PlanResourceServiceImpl extends BaseServiceImpl implements
		IPlanResourceService {
	
	private IPlanResourceDAO planResourceDAO;

	private IPlanTargetResourceDAO planTargetResourceDAO;
	
	public void setplanTargetResourceDAO(IPlanTargetResourceDAO planTargetResourceDAO){this.planTargetResourceDAO = planTargetResourceDAO;}
	
	public void setPlanResourceDAO(IPlanResourceDAO planResourceDAO){this.planResourceDAO = planResourceDAO;}

	public PageInfo getPageInfo(int iPageRecord, int iCurPage, List<ConditionUtil> lstConditionUtils) {
		String strCountHql = "select count(PlanResourceVO.planResourceId) from PlanResourceVO as PlanResourceVO where 1=1";
		String strRecordHql = "from PlanResourceVO where 1=1";
		return this.planResourceDAO.getPageInfo(strCountHql, strRecordHql, lstConditionUtils, iPageRecord, iCurPage);
	}

	public void deletePlanResourceVO(String[] strPlanResourceIds) {
		for(String strPlanResourceId : strPlanResourceIds){
			// 删除PlanResource实例
			this.planResourceDAO.delete("delete from PlanResourceVO where planResourceId=?", Integer.parseInt(strPlanResourceId));
			// 删除PlanResourceResource中间表关联数据
			this.planTargetResourceDAO.delete("delete from PlanResourceResourceVO as PlanResourceResourceVO where PlanResourceResourceVO.planResource.planResourceId=?", Integer.parseInt(strPlanResourceId));
		}
	}

	@SuppressWarnings("unchecked")
	public List<PlanResourceVO> findPlanResourceVOByUser(PubUserVO objPubUserVO) {
		return this.planResourceDAO.find("from PlanResourceVO where pubUser=? order by createDate", objPubUserVO);
	}

	public PlanResourceVO loadPlanResourceVO(Integer iPlanResourceId) {
		return this.planResourceDAO.getModel(PlanResourceVO.class, iPlanResourceId);
	}

	public void saveOrUpdatePlanResourceVO(PlanResourceVO objPlanResourceVO) {
		this.planResourceDAO.saveOrUpdateModel(objPlanResourceVO);
	}

	public void savePlanResourceVO(PlanResourceVO objPlanResourceVO) {
		this.planResourceDAO.saveModel(objPlanResourceVO);
	}

	
}
